package com.rabbiter.oes.controller;

import com.rabbiter.oes.entity.ApiResult;
import com.rabbiter.oes.entity.JudgeQuestion;
import com.rabbiter.oes.entity.MultiQuestion;
import com.rabbiter.oes.serviceimpl.JudgeQuestionServiceImpl;
import com.rabbiter.oes.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//多选题
@RestController
public class JudgeQuestionController {

    @Autowired
    private JudgeQuestionServiceImpl judgeQuestionService;

    @PostMapping("/judgeQuestion")
    public ApiResult add(@RequestBody JudgeQuestion judgeQuestion) {
        int res = judgeQuestionService.add(judgeQuestion);
        if (res != 0) {
            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }

    @GetMapping("/judgeQuestionId")
    public ApiResult findOnlyQuestionId() {
        JudgeQuestion res = judgeQuestionService.findOnlyQuestionId();
        return  ApiResultHandler.buildApiResult(200,"查询成功",res);
    }

    @PostMapping("/editJudgeQuestion")
    public ApiResult edit(@RequestBody JudgeQuestion judgeQuestion) {
        int res = judgeQuestionService.edit(judgeQuestion);
        if (res != 0) {
            return ApiResultHandler.buildApiResult(200,"修改成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"修改失败",res);
    }
    @GetMapping("/judgeQuestion/batch")
    public ApiResult getBatchQuestions(@RequestParam Integer count ,@RequestParam String subject) {
        System.out.println("subject:"+subject);
        List<JudgeQuestion> questions = judgeQuestionService.findRandom(count , subject);
        return ApiResultHandler.buildApiResult(200, "查询成功", questions);
    }

    @GetMapping("/judgeQuestion/sequence")
    public ApiResult getSequenceQuestions(@RequestParam String subject) {
        System.out.println("subject:"+subject);
        List<JudgeQuestion> questions = judgeQuestionService.findSequence(subject);
        return ApiResultHandler.buildApiResult(200, "查询成功", questions);
    }
}
